$(function(){
	/*两个输入框都有内容后激活按钮*/
	$('input').each(function(){
		$(this).bind('input propertychange',function(){
			if($('.land-phone').val() != '' && $('.land-ver').val() != ''){
				$('button').removeClass('disabled').removeAttr('disabled')
			}else{
				$('button').addClass('disabled').attr('disabled','true')
			}
		});
	});
	/*发送验证码倒计时*/
	$('.send-ver').click(function(){
		if($(this).find('span').text() == '发送验证码'){
			var alltime = 60;
			var time = setInterval(function(){
				if(alltime == 0){
					$('.send-ver span').text('发送验证码');
					$('.send-ver').addClass('send-grey');
					clearInterval(time);
				}else{
					alltime--;
					$('.send-ver span').text('('+alltime+')秒重新发送');
				}
			},1000);
			$('.send-ver span').text('('+alltime+')秒重新发送');
			$('.send-ver').removeClass('send-grey');
			$.ajax({
				type:'post',
				url: url() + "/user/sendCode",
				data:{
					cellphone:$('.land-phone').val(),
					type:0
				},
				dataType:'json',
				success:function(result) {
					//console.log(result);
					var alt = JSON.parse(result.result);
					if(result.code != 0 || alt.status != 0){
						alert(alt.message)
					};
					//localStorage.code = JSON.stringify(result);
				},
				error:function(){
					console.log('error')
				}
			})
		}
	});
	/*登录*/
	$('button').click(function(){
		/*防止用户多次连续点击，点一次禁止按钮点击*/
		$(this).attr('disabled',true);
		//console.log($('.land-phone').val())
		//console.log($('.land-ver').val())
		$.ajax({
			type:'post',
			url:url() + "/user/completeInfo",
			data:{
				cellphone:$('.land-phone').val(),
				verifyCode:$('.land-ver').val()
			},
			dataType:'json',
			success:function(result) {
				/*一次ajax请求结束后允许再次点击登录按钮*/
				$('button').removeAttr('disabled');
				//console.log(result);
				var alt = JSON.parse(result.result);
				if(result.code == 0 && alt.status == 0){
					window.location.href = url() + '/htm/index.html';
				}else{
					alert(alt.message)
				}
			},
			error:function(){
				/*一次ajax请求结束后允许再次点击登录按钮*/
				$('button').removeAttr('disabled');
				//console.log('error');
				alert('网络错误');
			}
		})
	})

})